#include <ximera/gui/cegui/combobox.hpp>
#include <ximera/common/utils.hpp>

namespace ximera { namespace gui { namespace cegui
{
    UInt32 Combobox::itemCount() const
    {
        return (UInt32)ceguiCombobox()->getItemCount();
    }

    void Combobox::addItem(String const& text)
    {
        ceguiCombobox()->addItem(new CEGUI::ListboxTextItem(string_util::wstr2str(text)));
    }

    void Combobox::removeItem(UInt32 index)
    {
        if (index >= itemCount())
            XIMERA_THROW(InvalidParamException, L"index is out of range!");

        CEGUI::ListboxItem* item = ceguiCombobox()->getListboxItemFromIndex(index);
        if (item)
            ceguiCombobox()->removeItem(item);
    }

    void Combobox::removeAllItems()
    {
        ceguiCombobox()->resetList();
    }

    Int32 Combobox::selectedIndex() const
    {
        CEGUI::ListboxItem* item = ceguiCombobox()->getSelectedItem();
        if (!item)
            return -1;

        return (UInt32)ceguiCombobox()->getItemIndex(item);
    }

    bool Combobox::readOnly() const
    {
        return ceguiCombobox()->isReadOnly();
    }

    void Combobox::readOnly(bool value)
    {
        ceguiCombobox()->setReadOnly(value);
    }

    bool Combobox::isDroppedDown() const
    {
        return ceguiCombobox()->isDropDownListVisible();
    }

    void Combobox::showDropDownList()
    {
        ceguiCombobox()->showDropList();
    }

    void Combobox::hideDropDownList()
    {
        ceguiCombobox()->hideDropList();
    }
}}}